package logManage

import (
	"github.com/gin-gonic/gin"
	"main/src/utils"
)

func GetLog(c *gin.Context) {
	body := &GetLogDto{}

	if err := utils.ShouldBind(c, &body); err != nil {
		return
	}
	Logs, err := body.Get(c)
	if err != nil {
		return
	}
	utils.Response(
		c,
		"ok",
		utils.Status.Ok,
		Logs,
	)
}

func CreateLog(c *gin.Context) {
	body := &CreateLogDto{}
	if err := utils.ShouldBind(c, &body); err != nil {
		return
	}
	user, err := body.Create(c)
	if err != nil {
		return
	}

	utils.Response(
		c,
		"ok",
		utils.Status.Ok,
		user,
	)
}

func UpdateLog(c *gin.Context) {
	body := &UpdateLogDto{}
	if err := utils.ShouldBind(c, &body); err != nil {
		return
	}
	content, err := body.UpdateContent(c)
	if err != nil {
		return
	}
	res := &LogInfoResponseDto{}
	res.format(*content)
	utils.Response(
		c,
		"ok",
		utils.Status.Ok,
		res,
	)
}

func DeleteLog(c *gin.Context) {
	body := &DeleteLogDto{}
	if err := utils.ShouldBind(c, &body); err != nil {
		return
	}
	if err := body.DeleteLog(c); err != nil {
		return
	}

	utils.Response(
		c,
		"ok",
		utils.Status.Ok,
		nil,
	)
}
